/*
 * Copyright (c) 2020-2030 Sishun.Co.Ltd. All Rights Reserved.
 */
package com.rabbitmq.demo.config;

import com.rabbitmq.demo.bean.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author ：lvfeilong
 * @version ：
 * @description ：
 * @program ：MySpringBoot
 * @date ：Created in 2021/4/8 14:17
 */
@Slf4j
@Component
public class DelayProducer {

    @Resource
    private AmqpTemplate amqpTemplate;

    public void sendOrder(Order order) {
        log.error("【订单:{}】已开始创建  【创建时间：{}】  【一分钟后检查是否支付成功】",order.toString(),new Date().toString());
        amqpTemplate.convertAndSend(RabbitMqConfig.ORDER_DELAY_EXCHANGE_NAME, RabbitMqConfig.ORDER_DELAY_ROUTING_KEY, order, message -> {
            message.getMessageProperties().setExpiration(String.valueOf(1000 * 60));
            return message;
        });
    }

}